<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        .a{
            width: 300px;
            height: 300px;
            background-color: #f00;
        }
        .b{
            width: 100px;
            height: 100px;
            background-color: #ff0;
        }

    </style>
</head>
<body>

    <div class="a">
        <div class="b">11</div>
    </div>

    <script>


        // 阻止事件冒泡
        //    子元素的事件会触发父元素的同类型事件
        //    阻止事件冒泡 --- 写在子元素身上



        var oA = document.querySelector('.a') ;
        var oB = document.querySelector('.b') ;

        oA.onclick = function() {
            console.log('a');
        }

        oB.onclick = function(e) {
            // e.stopPropagation() ;
            // e.cancelBubble = true ;   // IE
            if(e.stopPropagation) {
                e.stopPropagation()
            } else {
                e.cancelBubble = true ;
            }
            console.log('b');
        }

    </script>
    
</body>
</html>